<template>
  <div class="container">
    <div class="header">
      <div>
        <span class="title">单号：</span>
        <el-input v-model="search.order_sn" placeholder="请输入内容" size="medium" style="width:200px" />
      </div>

      <div>
        <span class="title">用户昵称：</span>
        <el-input v-model="search.name" placeholder="请输入内容" size="medium" style="width:200px" />
      </div>

      <div>
        <span class="title">创建时间：</span>
        <el-date-picker
          v-model="timer"
          size="medium"
          type="daterange"
          value-format="yyyy-MM-dd"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :clearable="false"
          :picker-options="pickerOptions"
          @change="selectTime"
        />
      </div>

      <div>
        <el-button size="small" type="primary" @click="reset">重置</el-button>
        <el-button size="small" type="primary" @click="getList">搜索</el-button>
      </div>
    </div>

    <div class="content">
      <el-table
        v-loading="loading"
        :data="list"
        :header-cell-style="{'color':'#000'}"
        style="width: 100%"
      >
        <el-table-column
          label="用户ID"
          width="100"
          align="center"
        >
          <template slot-scope="scope">
            {{ scope.row.user.id }}
          </template>
        </el-table-column>
        <el-table-column
          label="用户昵称"
          align="center"
          width="180"
        >
          <template slot-scope="scope">
            {{ scope.row.user.nickname || '—' }}
          </template>
        </el-table-column>
        <el-table-column
          label="用户手机号"
          align="center"
          width="180"
        >
          <template slot-scope="scope">
            {{ scope.row.user.phone || '—' }}
          </template>
        </el-table-column>
        <el-table-column
          label="性别"
          align="center"
          width="100"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.user.gender==1">男</span>
            <span v-if="scope.row.user.gender==2">女</span>
            <span v-if="scope.row.user.gender==0">未知</span>
          </template>
        </el-table-column>
        <el-table-column
          label="用户头像"
          align="center"
          width="180"
        >
          <template slot-scope="scope">
            <img :src="scope.row.user.avatar" alt="" style="width:60px;height:60px;object-fit: cover;border-radius: 10px;">
          </template>
        </el-table-column>
        <el-table-column
          prop="pay_money"
          label="充值金额（元）"
          align="center"
          width="180"
        />
        <el-table-column
          prop="pay_money"
          label="充值类型"
          align="center"
          width="180"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.pay_type==1">微信</span>
            <span v-if="scope.row.pay_type==2">支付宝</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="order_sn"
          label="单号"
          align="center"
          width="200"
        />
        <el-table-column
          prop="remarks"
          label="备注"
          align="center"
          width="200"
        />
        <el-table-column
          prop="pay_time"
          label="充值时间"
          align="center"
          width="180"
          fixed="right"
        />
      </el-table>
      <div v-if="total>10" class="pagination">
        <el-pagination
          :current-page="currentPage"
          layout="total, sizes, prev, pager, next, jumper"
          :page-size="pagesize"
          :page-sizes="[6, 10, 20, 30]"
          :total="total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      loading: false,
      timer: '',
      search: {
        order_sn: '',
        name: '',
        start_time: '',
        end_time: ''
      },

      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now()
        }
      },

      list: [],
      total: 0,
      pagesize: 10, // 默认一页10条
      currentPage: 1 // 当前页

    }
  },
  created() {
    this.getList()
  },
  methods: {
    // 重置
    reset() {
      this.currentPage = 1
      this.pagesize = 6
      this.search = {}
      this.timer = ''
      this.list = []
      this.getList()
    },

    // 获取表格数据
    getList() {
      this.loading = true
      this.$request.get('/admin/finance/recharge', {
        params: {
          ...this.search,
          limit: this.pagesize,
          page: this.currentPage
        }
      }).then(res => {
        this.loading = false
        this.list = res.data.data
        this.total = res.data.total
      }).catch(_ => { this.loading = false })
    },

    // 设置每页条数
    handleSizeChange(val) {
      this.pagesize = val
      this.getList()
    },
    // 分页
    handleCurrentChange(val) {
      this.currentPage = val
      this.getList()
    },

    // 选择时间
    selectTime(e) {
      this.search.start_time = e[0]
      this.search.end_time = e[1]
    }
  }
}
</script>

<style lang="scss" scoped>
  .header{
    width: 100%;
    height: auto;
    padding: 10px;
    background-color: #fff;
    display: flex;
    align-items: center;
    &>div{
        margin-right: 30px;
        &>.title{
            display: inline-block;
            font-size: 14px;
        }
    }
  }
  .content{
    width: 100%;
    margin-top: 10px;
  }
  .pagination{
    width: 100%;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #fff;
  }

  .btn{
    &>span{
      display: inline-block;
      color: #1989fa;
      width: 40px;
      text-align: center;
      cursor: pointer;
    }
  }
  .owner{
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    &>img{
      width: 60px;
      height: 60px;
      object-fit: cover;
      border-radius: 10px;
    }
    &>div{
      width: calc(100% - 80px);
    }
  }

  .redPacket{
    padding-left: 20px;
  }
  .look{
    width: 100%;
    font-size: 14px;
    color: #1989fa;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    &>span{ margin-left: 10px; }
  }
</style>
